package z.nat;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {

    private static Activity activity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout);
        activity=this;

        Button button = findViewById(R.id.bb);
        button.setOnClickListener(v -> {
            if (MyService.running) {
                Toast.makeText(this, "停止", Toast.LENGTH_SHORT).show();
                stopService(new Intent(this, MyService.class));
                return;
            }
            Toast.makeText(this, "启动...", Toast.LENGTH_SHORT).show();
            startService(new Intent(this, MyService.class));
        });
    }

    public static void toast(String s){
        activity.runOnUiThread(()->Toast.makeText(activity,s,Toast.LENGTH_LONG).show());
    }


}
